﻿using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.AI
{
    public class CurveSpeedStrategy : SpeedStrategy
    {
        public AnimationCurve speedCurve = AnimationCurve.Linear(0,0,1,1);

        [Header("开始减速的半径")]
        public float decRadius = 3f;

        public float innerRadius = 0.2f;

        public float speedOffset = 0.05f;

        public float speed;

        public Vector3 lastTargetVector = Vector3.zero;
        
        public override float GetSpeed(float originSpeed, Vector3 mTargetVector)
        {
            mTargetVector.y = 0;
            float targetDistance = mTargetVector.magnitude;

            speed = originSpeed * speedCurve.Evaluate((targetDistance - innerRadius) / (decRadius - innerRadius));
            if (speed < speedOffset)
            {
                speed = 0f;
            }

            lastTargetVector = mTargetVector;

            return speed;
        }
    }
}